import { createStore } from 'vuex'

export default createStore({
  state: {
    memberInfo: [
      {
        name: 'A队',
        score: 100
      },
      {
        name: 'B队',
        score: 100
      },
      {
        name: 'C队',
        score: 100
      },
      {
        name: 'D队',
        score: 100
      },
      {
        name: 'E队',
        score: 100
      },
      {
        name: 'F队',
        score: 100
      },
      {
        name: 'G队',
        score: 100
      },
      {
        name: 'H队',
        score: 100
      }
    ],
    ruleIndex:-1,
    rushIndex:0
  },
  //类似计算属性
  getters: {
    getTableData(state){
        return state.memberInfo.concat().sort((a, b) => { return b.score - a.score })
    }
  },
  //同步改变
  mutations: {
    addScore (state, [index, score]) {
      state.memberInfo[index].score += score;
    },
    subScore (state, [index, score]) {
      state.memberInfo[index].score -= score;
    },
    setRuleIndex(state,index){
      state.ruleIndex = index;
    },
    setRushIndex(state,index){
      state.rushIndex = index;
    },
  },
  actions: {//可以执行一些异步请求之类的
  },
  modules: {
  }
})